<?php
/**
 * Created by PhpStorm.
 * User: 海峡
 * Date: 2020/11/5
 * Time: 11:52
 */
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Admin\Menu;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;

class IndexController extends Controller
{
    public function index()
    {
//        dd(session('admin.menu'));
        $data = getTree(Menu::whereIn('id',session('admin.menu'))->get());

        foreach ($data as $k=>$val){
            if($val['pid']==0){
                $menus[$k]['name']=$val['menu_name'];
                $menus[$k]['url']=$val['url'];
                $menus[$k]['menulist'] = Menu::where('pid',$val['id'])->whereIn('id',session('admin.menu'))->get(['name','url'])->toArray();
            }
        }
        return view('admin.index',compact('menus'));
    }

    public function welcome()
    {
        return view('admin.welcome');
    }

    public function error()
    {
        return view('admin.error');
    }

    public function logout()
    {
        auth()->guard('admin')->logout();
        return redirect(url('admin'));
    }
}
